package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.aop_whh.annotation.OperateLog;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.PermissionDTO;
import com.cskaoyan.wordmemorize.request.PermissionCommand;
import com.cskaoyan.wordmemorize.service.RolePermissionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/permission")
public class PermissionController {
    @Resource
    RolePermissionService rolePermissionService;
    //获取账号权限列表
    @RequestMapping("list")
    public Result<List<PermissionDTO>> getPermissionList() {
        List<PermissionDTO> permissions = rolePermissionService.getPermissions();
        return Result.ok(permissions);
    }
    //添加账号权限
    @PostMapping()
    @OperateLog(dateType = "账号权限",operateType = 1)
    public Result<String> addPermission(@RequestBody PermissionCommand command) {
        rolePermissionService.savePermissions(command);
        return Result.ok("成功");
    }
    //修改账号权限
    @PutMapping()
    @OperateLog(dateType = "账号权限",operateType = 4)
    public Result<String> updatePermission(@RequestBody PermissionCommand command) {
        rolePermissionService.updatePermission(command);
        return Result.ok("成功");
    }
    //删除指定账号权限
    @DeleteMapping("{permissionId}")
    @OperateLog(dateType = "账号权限",operateType = 2)
    public Result<String> deletePermission(@PathVariable("permissionId") Long permissionId) {
        rolePermissionService.deletePermission(permissionId);
        return Result.ok("成功");
    }
}
